import Vue from "vue";
import Vuex from 'vuex'

Vue.use(Vuex)

const actions = {

}
const mutations = {
    getData(state, value) {
        state.message = value
    },
    AddFriendList: (state, [value1, value2]) => {

        for (let index = 0; index < state.FrinendList.length; index++) {
            if (state.FrinendList.name == value2) {
                state.FrinendList[index].ChatInfo.push(value1)
            }
        }
    },
    AddGroupList: (state, [value1, value2]) => {
        for (let index = 0; index < state.GroupList.length; index++) {
            if (state.GroupList.name == value2) {
                state.GroupList[index].ChatInfo.push(value1)
            }
        }
    }
}
const state = {
    FrinendList: [//存储当前对象的好友信息
        {
            account: '18120846839',
            name: '18120846839',
            ChatInfo: [
            ],
            alive: false
        },
        {
            account: '123',
            name: '123',
            ChatInfo: [
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:21'
                },
                {
                    person: 'Junjie',
                    words: 'Hi!',
                    time: '12:23'
                },
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:24'
                },
            ],
            alive: false
        },
        {
            account: '18120846839',
            name: 'LiaoJunjie',
            ChatInfo: [
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:21'
                },
                {
                    person: 'LiaoJunjie',
                    words: 'Hi!',
                    time: '12:23'
                },
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:24'
                },
            ],
            alive: false
        },
        {
            account: '181',
            name: 'bang',
            ChatInfo: [
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:00'
                },
                {
                    person: 'bang',
                    words: 'Hi!',
                    time: '12:11'
                },
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:21'
                },
                {
                    person: 'bang',
                    words: 'Hi!',
                    time: '12:23'
                },
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:24'
                },
                {
                    person: 'bang',
                    words: 'this.UserInfo.info = this.$route.params.info;this.UserInfo.account = this.$route.params.account',
                    time: '12:25'
                }
            ],
            alive: false
        }
    ],
    GroupList: [//存储当前对象的群聊信息
        {
            name: 'Chat Room1',
            account: '1234567',
            member: [
                {
                    account: '18120846839',
                    username: 'Liao1'
                },
                {
                    account: '19914700618',
                    username: 'Junjie'
                },
                {
                    account: '18120846839',
                    username: 'LiaoJunjie'
                }
            ],
            ChatInfo: [
                {
                    person: 'Liao Chat Room1',
                    words: 'Hello!',
                    time: '12:21'
                },
                {
                    person: 'Junjie',
                    words: 'Hi!',
                    time: '12:23'
                },
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:24'
                },
            ]
        },
        {
            name: 'Chat Room2',
            account: '12345678',
            member: [
                {
                    account: '18120846839',
                    username: 'Liao'
                },
                {
                    account: '19914700618',
                    username: 'Junjie'
                },
                {
                    account: '18120846839',
                    username: 'LiaoJunjie'
                }
            ],
            ChatInfo: [
                {
                    person: 'Liao Chat Room2',
                    words: 'Hello!',
                    time: '12:21'
                },
                {
                    person: 'Junjie',
                    words: 'Hi!',
                    time: '12:23'
                },
                {
                    person: 'Liao',
                    words: 'Hello!',
                    time: '12:24'
                },
            ]
        }
    ]
}
export default new Vuex.Store({
    actions,
    mutations,
    state
})